package com.laowang.project.system.controller;

import java.util.List;

import com.laowang.framework.web.page.TableDataInfoMy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyBanner;
import com.laowang.project.system.service.MyBannerService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * bannerController
 *
 * @author laowang
 * @date 2023-04-19
 */
@Api(tags = "banner接口")
@RestController
@RequestMapping("/banner")
public class MyBannerController extends BaseController {
    @Autowired
    private MyBannerService myBannerService;

    /**
     * 查询banner列表
     */
    @ApiOperation(value = "小程序端 查询banner列表",notes = "")
    @GetMapping("/web/list")
    public TableDataInfoMy weblist(MyBanner myBanner) {
        startPage();
        myBanner.setStatus("0");
        List<MyBanner> list = myBannerService.selectMyBannerList(myBanner);
        return getDataTableMy(list);
    }


    /**
     * 查询banner列表
     */
    @ApiOperation(value = "后台管理 查询banner列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyBanner myBanner) {
        startPage();
        List<MyBanner> list = myBannerService.selectMyBannerList(myBanner);
        return getDataTable(list);
    }

    /**
     * 导出banner列表
     */
    @ApiOperation(value = "导出banner列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:banner:export')")
    //@Log(title = "banner", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MyBanner myBanner) {
        List<MyBanner> list = myBannerService.selectMyBannerList(myBanner);
        ExcelUtil<MyBanner> util = new ExcelUtil<MyBanner>(MyBanner.class);
        return util.exportExcel(list, "banner");
    }

    /**
     * 获取banner详细信息
     */
    @ApiOperation(value = "获取banner详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(myBannerService.selectMyBannerById(id));
    }

    /**
     * 新增banner
     */
    @ApiOperation(value = "新增banner",notes = "")
    @PreAuthorize("@ss.hasPermi('my:banner:add')")
    //@Log(title = "banner", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyBanner myBanner) {
        return toAjax(myBannerService.insertMyBanner(myBanner));
    }

    /**
     * 修改banner
     */
    @ApiOperation(value = "修改banner",notes = "")
    @PreAuthorize("@ss.hasPermi('my:banner:edit')")
    //@Log(title = "banner", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyBanner myBanner) {
        return toAjax(myBannerService.updateMyBanner(myBanner));
    }

    /**
     * 删除banner
     */
    @ApiOperation(value = "删除banner",notes = "")
    @PreAuthorize("@ss.hasPermi('my:banner:remove')")
    //@Log(title = "banner", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myBannerService.deleteMyBannerByIds(ids));
    }
}
